package top.lingkang.finalsession;

import top.lingkang.finalsession.core.FinalGenerateSession;
import top.lingkang.finalsession.core.FinalRepository;
import top.lingkang.finalsession.core.FinalSessionHandler;
import top.lingkang.finalsession.core.IdGenerate;
import top.lingkang.finalsession.javax.GenerateSessionJavax;
import top.lingkang.finalsession.javax.MemoryFinalRepository;

/**
 * @author lingkang
 * @create by 2024/5/10 9:19
 */
public class FinalSessionConfig {
    // 会话的名称，默认是cookie的名称
    private String sessionName = "fs";

    // session 存在最大时间，单位毫秒。默认 30 分钟
    private long maxValidTime = 1800000L;

    // 每次访问是否更新最后访问时间，即续时功能。默认启用
    private boolean isUpdateAccessTime = true;

    // 保留时间，即每次执行访问操作后台，预留1分钟，防止会话失效的极限时间，在 accessUpdateTime=false 时启用
    private long reserveTime = 60000L;

    /**
     * 生成id，默认uuid
     */
    private IdGenerate idGenerate;

    /**
     * 会话存储，默认存储于内存中: {@link MemoryFinalRepository}
     */
    private FinalRepository repository;

    /**
     * 生成session <br>
     * javax.servlet.http 中默认实现类 {@link GenerateSessionJavax}<br>
     */
    private FinalGenerateSession generateSession;

    /**
     * 绑定、获取session处理：<br>
     * javax.servlet.http 中默认实现类 {@link top.lingkang.finalsession.javax.FinalSessionHandlerCookie}<br>
     */
    private FinalSessionHandler sessionHandler;

    public String getSessionName() {
        return sessionName;
    }

    public FinalSessionConfig setSessionName(String sessionName) {
        this.sessionName = sessionName;
        return this;
    }

    public long getMaxValidTime() {
        return maxValidTime;
    }

    public FinalSessionConfig setMaxValidTime(long maxValidTime) {
        this.maxValidTime = maxValidTime;
        return this;
    }

    public IdGenerate getIdGenerate() {
        return idGenerate;
    }

    public FinalSessionConfig setIdGenerate(IdGenerate idGenerate) {
        this.idGenerate = idGenerate;
        return this;
    }

    public boolean isUpdateAccessTime() {
        return isUpdateAccessTime;
    }

    public FinalSessionConfig setUpdateAccessTime(boolean updateAccessTime) {
        isUpdateAccessTime = updateAccessTime;
        return this;
    }

    public long getReserveTime() {
        return reserveTime;
    }

    public FinalSessionConfig setReserveTime(long reserveTime) {
        this.reserveTime = reserveTime;
        return this;
    }

    public FinalRepository getRepository() {
        return repository;
    }

    public FinalSessionConfig setRepository(FinalRepository repository) {
        this.repository = repository;
        return this;
    }

    public FinalGenerateSession getGenerateSession() {
        return generateSession;
    }

    public FinalSessionConfig setGenerateSession(FinalGenerateSession generateSession) {
        this.generateSession = generateSession;
        return this;
    }

    public FinalSessionHandler getSessionHandler() {
        return sessionHandler;
    }

    public FinalSessionConfig setSessionHandler(FinalSessionHandler sessionHandler) {
        this.sessionHandler = sessionHandler;
        return this;
    }
}
